<?php

namespace app\admin\model;

use think\Db;
use think\Model;

class OperationModel extends Model
{

    // 设置数据表（不含前缀）
    protected $name = 'operation';
    // 设置当前模型对应的完整数据表名称
    protected $table = 'ld_operation';

    public function __construct($data = [])
    {
        parent::__construct($data);
    }


    /**
     * @param $oper
     * @return bool
     * @param 写入操作日志
     */
    public function addlog($oper){
        // 启动事务
        Db::startTrans();
        try{
            $query = Db::name($this->name)->insert($oper);
            // 提交事务
            Db::commit();
            return $query;
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
            return false;
        }
    }

    /**
     * @param $where
     * @param $page
     * @param $limit
     * @param 操作日志列表
     */
    public function userlist($where,$page,$limit){
        $query = Db::name($this->name)->where($where)->order('addTime desc')->page($page)->limit($limit)->select();
        return $query;
    }

    public function county($where){
        $query = Db::name($this->name)->where($where)->count();
        return $query;
    }


}